/*
    XTU OJ: 1478
    by: fifth_light
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

char string[2048];
int l;
int slice_l;

int strcmp_len(const char* a, const char* b) {
    for (int i = 0; i < slice_l; i++) {
        if (a[i] > b[i]) {
            return 1;
        } else if (a[i] < b[i]) {
            return -1;
        }
    }
    return 0;
}

int compar_string(const void* a, const void* b) {
    return strcmp_len((const char*) a, (const char*) b);
}

int slice(int last_val, int slice_len) {
    int result = last_val;
    if (l == slice_len) {
        result++;
    } else if (slice_len == 1) {
        int letters[26] = {0};
        for (int i = 0; i < l; i++) {
            int n = string[i] - 'a';
            if (letters[n] == 0) {
                result++;
                letters[n] = 1;
            }
        }
    } else {
        int slice_cnt = l / slice_len;
        char ostr[2048];
        strcpy(ostr, string);
        slice_l = slice_len;
        // qsort上场
        // printf("%s\n", ostr);
        qsort(ostr, slice_cnt, slice_len, compar_string);
        // printf("%s\n", ostr);
        for (int i = 0; i < slice_cnt; i++) {
            if (i == 0) {
                result++;
            } else {
                if (strcmp_len(ostr + (i - 1) * slice_len, ostr + i * slice_len) != 0) {
                    result++;
                }
            }
        }
    }
    // printf("slice_len: %d, result: %d\n", slice_len, result);
    if (slice_len == 1) {
        return result;
    } else {
        return slice(result, slice_len / 2);
    }
}

int main() {
    int t;
    scanf("%d", &t);
    for (int i = 0; i < t; i++) {
        int l1, l2;
        scanf("%n%s%n", &l1, string, &l2);
        l = l2 - l1 - 1;
        if (l == 1) {
            puts("1");
            continue;
        }
        printf("%d\n", slice(0, l));
    }
    return 0;
}
